package com.qk.management.service.Impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.qk.common.PageResult;
import com.qk.entity.Dept;
import com.qk.management.mapper.DeptMapper;
import com.qk.management.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 *
 *
 * @author blusr
 * @version 1.0
 * @date 2025/9/29 10:33
 */
@Service
@SuppressWarnings("all")
public class DeptServiceImpl implements DeptService {
    @Autowired
    private DeptMapper deptMapper;
    @Override
    public void addDept(Dept dept) {
        dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.insert(dept);
    }

    @Override
    public PageResult<Dept> page(String name, Integer status, Integer page, Integer pageSize) {
        PageHelper.startPage(page, pageSize);
        List<Dept> depts = deptMapper.list(name, status);
        Page<Dept> rs =  (Page<Dept>) depts;
        return PageResult.<Dept>builder()
                .total(new Long(rs.getTotal()).intValue())
                .rows(rs.getResult())
                .build();
    }

    @Override
    public Dept getDeptById(Integer id) {
        return deptMapper.selectById(id);
    }

    @Override
    public void updateDept(Dept dept) {
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.update(dept);
    }

    @Override
    public void deleteDept(Integer id) {
        deptMapper.delete(id);
    }

    @Override
    public List<Dept> listDept() {
        return deptMapper.listDept();
    }


}
